package com.eascs.spider.yuqing.common.proj;

import java.io.Serializable;
import java.util.Comparator;
/**
 * 优先级任务对象实体
 * @author hzp
 *
 */
public class PriorityTask implements Serializable{

	private static final long serialVersionUID = 3780905476090820014L;

	private String url;//待处理的url
	
	private PriorityAttr priority;//优先级
	
	public PriorityTask(String url , PriorityAttr priority){
		this.url = url;
		this.priority = priority;
	}
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public PriorityAttr getPriority() {
		return priority;
	}

	public void setPriority(PriorityAttr priority) {
		this.priority = priority;
	}

	//优先级列项
	public enum PriorityAttr{
		HIGH(3) , NORMAL(2) , LOW(1);
		
		private int level;//优先级的数字表示
		
		private PriorityAttr(int level){
			this.level = level;
		}
		
		private int getLevel(){
			return this.level;
		}
	}
	
	//获得比较器
	public static Comparator<PriorityTask> getComparator(){
		return new Comparator<PriorityTask>() {
			public int compare(PriorityTask o1 , PriorityTask o2){
				int level1 = o1.getPriority().getLevel();
				int level2 = o2.getPriority().getLevel();
				if(level2 > level1)
					return 1;
				else if(level2 < level1)
					return -1;
				else
					return 0;
			}
		};
	}
}
